package com.example.doctor.jpa;

import com.example.common.entity.DoctorGroupPatients;
import org.springframework.data.repository.query.Param;
import org.apache.ibatis.annotations.Delete;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

import javax.transaction.Transactional;

public interface DoctorGroupPatientsrRepository extends JpaRepository<DoctorGroupPatients,Long> {

    @Query(value = "SELECT COUNT(id_bigint) as count FROM doctor_group_patients WHERE gid_bigint=:gid",nativeQuery = true)
    Integer findByDcIdAndCount(@Param("gid") Long gid);

    @Query(value = "select count(1) from rel_dr_and_patients a"
    +" inner join client_patients_info b on a.pid_bigint = b.pid_bigint"
    +" where dc_id_bigint = :dcid and b.disable_bit = 0",nativeQuery = true)
    Integer findCountAllByDcId(@Param("dcid") Long dcid);

    @Query(value = "SELECT * FROM doctor_group_patients WHERE gid_bigint != :Gid and pid_bigint = :pid",nativeQuery = true)
    List<DoctorGroupPatients> findAllByPidOtherGid(@Param("Gid") Long Gid, @Param("pid") Long pid);

    List<DoctorGroupPatients> findAllByPidAndGid(Long pid, Long Gid);

    // void deleteByPid(long longValue);

    @Delete(value = "delete from doctor_group_patients where gid_bigint = :gid")
    void deleteByGid(@Param("gid") Long gid);
}
